package actions.commons;

import java.util.List;

import services.commons.CommonsService;
import actions.base.SecureAction;

import com.google.gson.Gson;

import dto.LocalidadDTO;
import dto.ProvinciaDTO;

public class CommonsAction extends SecureAction {

	private CommonsService commonsService;
	
	@Override
	public String execute() {
		return SUCCESS;
	}
	
	public String getLocalidades() {
		
		List<LocalidadDTO> localidades = commonsService.getAllLocalidades();
		
		Gson gson = new Gson();
		String localidadesStr = gson.toJson(localidades);
		
		setLista(localidadesStr);
		return SUCCESS_LISTADO;
	}
	
	public String getProvincias() {
		
		List<ProvinciaDTO> provincias = commonsService.getAllProvincias();
		
		Gson gson = new Gson();
		String provinciasStr = gson.toJson(provincias);
		
		setLista(provinciasStr);
		return SUCCESS_LISTADO;
	}

	public CommonsService getCommonsService() {
		return commonsService;
	}

	public void setCommonsService(CommonsService commonsService) {
		this.commonsService = commonsService;
	}
	
}
